import LogFactory from "@/log/LogFactory.ts";
import {Link, useLocation} from "react-router-dom";
import {SecurityUser} from "@/type/SecurityUser";
import {Card, Tabs, TabsProps, Tag} from "antd";
import {MenuOutlined, UserOutlined} from "@ant-design/icons";
import UserAuthMenu from "@/component/admin/user/UserAuthMenu.tsx";
import UserAuthRole from "@/component/admin/user/UserAuthRole.tsx";
import {useRef} from "react";

const log = LogFactory.getLogger("UserAuthComponent");

const items: TabsProps["items"] = [
    {
        key: "user_role_authority",
        label: "用户角色权限",
        children: <UserAuthRole/>,
        icon: <UserOutlined />
    },
    {
        key: "user_menu_authority",
        label: "用户菜单权限",
        children: <UserAuthMenu/>,
        icon: <MenuOutlined />
    }
]
type UserAuthKeyType = "user_menu_authority" | "user_role_authority";
const UserAuthComponent = () => {
    const user = useLocation().state as SecurityUser;
    const keyRef = useRef<UserAuthKeyType>("user_menu_authority");
    // log.debug("user ", user);
    log.debug("用户权限管理组件加载");
    return (
        <Card title={"用户权限管理 - " + user.username} extra={ <Link to={".."}>用户列表</Link> }>
            <Tabs
                tabBarExtraContent={<Tag color={"rgba(122,87,23,0.45)"}>{user.identity}</Tag>}
                defaultActiveKey={keyRef.current}
                items={items}
                animated
                destroyInactiveTabPane
                onTabClick={key => {

                    // keyRef.current = key as UserAuthKeyType;
                    log.debug("点击tab: ", key)
            }}
        />
        </Card>
    );
};

export default UserAuthComponent;